[1] 3
Post your thoughts…
https://jamboard.google.com/d/1LpJL4xq66UWPS0LVQ7gKJ2qKj5q-ivQetItGH26urls/edit?usp=sharing
Steep Learning Curve Ahead
R can be used to do basic math…
[1] 3
Calculations follow PEMDAS order of operations: Parenthesis, Exponents, Multiplication, Division, Addition and Subtraction.
[1] 12
[1] 12
[1] 24
A variable can store any data type (e.g. numeric, character, date, logical) or object (e.g. functions, vectors, plots).
[1] 5
[1] 25
Remove a variable from the environment with the function rm.
A vector is a collection of elements of the same type. Operations can be applied to each element of the vector automatically.
[1] 1 2 3 4 5
[1] 2 4 6 8 10
[1] -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
[1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
[13] TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE
my_script.R that:
my_name with your namemy_number with your lucky numbermy_vector with a vector of 5 numbersmy_vector by my_numberInstall new packages: install.packages("PACKAGE_NAME")
Use package functions in environment: library(PACKAGE_NAME)
! Notice that installing packages requires the package name in quotes (” or ’), but calling the library function does not
See list of installed packages with installed.packages
swirl R packageswirl is a package with a great collection of interactive R courses.
Install swirl: install.packages("swirl")
Bring the package into your environment and install the “R Programming Course”:
library(swirl)
install_course("R Programming")
swirl R packageType
and select the first lesson, 1: Basic Building Blocks.
What symbol is used to assign a value to a variable?
What does c() do?
How can you quickly bring up help on a function?
What is the output of
[1] 1 2 20
4 main types: numeric, character, Date/POSIXct, and logical
| Data Type | Description | Examples |
|---|---|---|
| numeric | integers, decimals, positive, negative numbers | 500, 3.4, -6, 0 |
| character (or factor) | text data; factor data types have “levels” | “Hello world”, c(“agree”, “disagree”, “neutral”) |
| Data Type | Description | Examples | Helper Functions |
|---|---|---|---|
| dates | date or POSIXct (date & time) | “2019-01-25”, “June 20 2007”, “Fri Sep 16 21:07:56 2022” | Sys.Date, date, as.Date, format, functions from the lubridate package |
| logical | true or false (true = 1 and false = 0 in numeric form) | 2 == 3, 6 != 5, 2 < 3 | is.logical |
Reveal the data type of any variable using the class function.
[1] "numeric"
[1] "character"
Factors are vectors used to work with categorical variables and have a known and fixed set of values.
[1] "character"
[1] "Feb" "Jan" "Mar"
[1] "Feb" "Jan" "Mar"
The levels are an attribute of factors that define all possible elements and can define the order.
[1] Jan Feb Mar
Levels: Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
Functions automate tasks and make code repeatable. So far, we’ve used several base R functions like class, as.factor, and sort.
Structure:
where arguments pass the function the needed information in order to complete the function’s task. Note: not all functions need arguments (e.g. getwd() )
Get help or documentation on a function using the ? operator.
https://copilot.microsoft.com/
Use VCU student credentials.
Data Exploration
Data Wrangling
Happy coding!